package com.example.psysystemhomework.alert;

import android.app.AlertDialog;
import android.content.Context;
import android.view.View;
import android.widget.Toast;

import com.example.psysystemhomework.R;
import com.example.psysystemhomework.bean.EmotionTo;
import com.example.psysystemhomework.bean.UserBean;
import com.example.psysystemhomework.util.ChartUtil;
import com.example.psysystemhomework.util.NetUtil;
import com.example.psysystemhomework.util.ShareUtil;
import com.github.mikephil.charting.charts.HorizontalBarChart;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class HoriAlert extends AlertDialog {
    Context context;
    private HorizontalBarChart horChart;
    private ArrayList<EmotionTo> list;

    public HoriAlert(Context context, ArrayList<EmotionTo> list) {
        super(context);
        this.context = context;
        this.list = list;
    }

    public HoriAlert(Context context) {
        super(context);
        this.context = context;
    }

    public HoriAlert(Context context, boolean cancelable, OnCancelListener cancelListener, Context context1) {
        super(context, cancelable, cancelListener);
        this.context = context;
    }

    public void showChart() {
        ShareUtil shareUtil = new ShareUtil(context);
        UserBean user = shareUtil.getUser();
        if (user == null) {
            Toast.makeText(context, "请先登录", Toast.LENGTH_SHORT).show();
        } else {
            View inflate = View.inflate(context, R.layout.hori_chart_layout, null);
            initViews(inflate);
            ChartUtil chartUtil = new ChartUtil(horChart);
            chartUtil.showHoriBarChart(list);
            setView(inflate);
            show();
        }

    }


    private void initViews(View view) {
        horChart = view.findViewById(R.id.horChart);
    }


}
